package com.itheima.health.controller;

import com.itheima.health.dto.CheckGroupDTO;
import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.entity.Result;
import com.itheima.health.service.CheckGroupService;
import com.itheima.health.service.ReportService;
import com.itheima.health.utils.date.DateUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.Map;

//
@RestController
@Api(tags = "报表管理开发")
public class ReportController {

    // springmvc  消息转化器   @ResponseBody  默认 全字段序列化

    @Reference
    private ReportService reportService;

    @GetMapping("report/findMemberCountsByMonth/{start}/{end}")
    public Result  findMemberCountsByMonth(@PathVariable("start") Date start, @PathVariable("end") Date end ){
        String begin = DateUtils.parseDate2String(start, "yyyy-MM")+"-01";
        String over = DateUtils.parseDate2String(end, "yyyy-MM")+"-31";
        return  new Result(reportService.findMemberCountsByMonth(begin,over));

    }
    @GetMapping("report/getSetmealProportion")
    public Result  getSetmealProportion( ){
        return  new Result(reportService.getSetmealProportion());

    }

    @ApiOperation(value = "会员统计功能",notes = "查询男女会员占比")
    @GetMapping("/report/queryTheRatioBySex")
    public Result queryTheRatioBySex(){
        return new Result(reportService.queryTheRatioBySex());
    }

    @ApiOperation(value = "会员统计功能",notes = "查询各个年龄段的会员占比")
    @GetMapping("report/QueryTheProportionAccordingToAge")
    public Result QueryTheProportionAccordingToAge(){
        return new Result(reportService.QueryTheProportionAccordingToAge());
    }

    @ApiOperation(value = "运营报表统计功能",notes = "运营报表和热门套餐")
    @GetMapping("report/operatingStatistics")
    public Result OperatingStatistics(){
        Map map=reportService.operatingStatistics();
        return new Result(map);
    }

    @ApiOperation(value = "导出功能",notes = "导出运营数据生成Excel")
    @PostMapping("report/basedOnDataExportExcels")
    public Result exportExcels(@RequestBody Map map){
        try {
            reportService.exportExcels(map);
            return  new Result(true, "Excel表格导出成功!");
        } catch (Exception e) {
            e.printStackTrace();
            return  new Result(false, "Excel表格导出失败！");
        }
    }
}
